package cn.edu.lzu.dao;

import cn.edu.lzu.entity.ExamineItem;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @PackageName: cn.edu.lzu.dao
 * @InterfaceName: ExamineItemMapper
 * @Description: TODO
 * @Author: 张琦[QQ:3098086691]
 * @Date: 2019/12/8 20:01
 * @Version: 1.0
 */
@Mapper
public interface ExamineItemMapper {

    @Select("select * from examine_item where is_deleted=0 and unit_id = #{unitId} limit #{startIndex}, #{pageSize}")
    List<ExamineItem> selPageExamineItemNotDeletedByUnitId(long unitId, int startIndex, int pageSize);

    @Select("select count(*) from examine_item where is_deleted=0 and unit_id = #{unitId}")
    int selItemTotalCountByUnitId(long unitId);

    @Insert("insert into examine_item (examine_item_id, examine_name, item_type_id, apply_sex, apply_range, price, unit_id, is_deleted, fill_status)  values(default, #{examineName}, #{itemTypeId}, #{applySex}, #{applyRange}, #{price}, #{unitId}, 0,  0)")
    int insExamineItem(ExamineItem examineItem);

    @Update("update examine_item set is_deleted=1 where examine_item_id = #{examineItemId}")
    int updDeleteExamineItemByItemId(int examineItemId);

    @Update("update examine_item set is_deleted=1 where examine_item_id in (${examineItemIds})")
    int updBatchSetIsDeletedTrue(String examineItemIds);

    @Update("update examine_item set fill_status=1 where examine_item_id=#{examineItemId}")
    int updSetFillStatusTrue(long examineItemId);

    @Select("select examine_item_id from examine_item where is_deleted=0 and unit_id=#{unitId} and item_name like concat('%', #{itemName}, '%')")
    List<Integer> getExamineItemIdByName(long unitId, String itemName);






    @Select("select * from examine_item where is_deleted=0 and unit_id = #{unitId}")
    List<ExamineItem> selAllExamineItemNotDeletedByUnitId(long unitId);

    @Select("select max(examine_item_id) from examine_item")
    int selMaxExamineItemId();



    @Select("select * from examine_item where is_deleted=0 and unit_id=#{unitId} and examine_item_id like concat('%', #{examineItemId}, '%') limit #{startIndex}, #{pageSize}")
    List<ExamineItem> selFuzzyPageExamineItemById(long unitId, int examineItemId, int startIndex, int pageSize);

    @Select("select * from examine_item where is_deleted=0 and unit_id=#{unitId} and item_name like concat('%', #{itemName}, '%') limit #{startIndex}, #{pageSize}")
    List<ExamineItem> selFuzzyPageExamineItemByName(long unitId, String itemName, int startIndex, int pageSize);

    @Select("select * from examine_item where is_deleted=0 and unit_id=#{unitId}")
    List<ExamineItem> selExamineItemsByTypeId(long unitId);

    @Select("select * from examine_item where is_deleted=0 and examine_item_id=#{examineItemId}")
    ExamineItem selByExamineItemId(int examineItemId);



}
